package com.haoyu.microservicecloudprovidercategory8001.controller;

import com.haoyu.microservicecloudapi.entity.Category;
import com.haoyu.microservicecloudprovidercategory8001.service.CategoryService;
import com.netflix.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: 蒿雨
 * @create: 2022-04-12 11:58
 * @description:
 */
@RestController
public class CategoryController {

    @Resource
    private CategoryService categoryService;

//    @Resource
//    DiscoveryClient client;

    //查询微服务信息
    @RequestMapping("/discovery")
    public Object discovery() {
        return null;
    }


    @GetMapping("/category")
    public List<Category> list() {
        return categoryService.list();

    }

    @GetMapping("/{id}/category")
    public Category get(@PathVariable Integer id) {
        return categoryService.getById(id);

    }

    @PutMapping("/category")
    public boolean update(@RequestBody Category category) {
        return categoryService.updateById(category);
    }

    @PostMapping("/category")
    public boolean insert(@RequestBody Category category) {
        return categoryService.save(category);
    }

    @DeleteMapping("/category")
    public boolean delete(@PathVariable Integer id) {
        return categoryService.removeById(id);
    }

}
